package priv.mill.guessq;

import java.util.Scanner;

public class TestPlay {

	 static User user;
	 static Computer computer;
	 static Scanner scanner;
	 static int count;

	public static void main(String[] args) {
		// 初始化游戏
		initPlay();
		// 开始游戏
		playStart();
		// 计算结果
		// 显示结果
	}

	private static void playStart() {
		// 1、输出游戏界面
		System.out.println("==================欢迎来到猜拳游戏===================");
		System.out.println("游戏规则如下：");

		System.out.println("============================================");

		// 2、显示游戏规则
		// 3、提示用户选择对战角色
		System.out.println("请选择角色：1.赵云。2.诸葛亮。3.大乔");
		scanner = new Scanner(System.in);
		switch (scanner.nextInt()) {
		case 1:
			user.setName("赵云");
			break;
		case 2:
			user.setName("诸葛亮");
			break;
		case 3:
			user.setName("大乔");
			break;

		default:
			user.setName("阿斗");
			break;
		}

		// 4、提示用户出拳，用户和计算机出拳，并提示结果.x,y.x+1==y.x-2==y
		int result;

		System.out.println("请出拳:1、石头；2、剪刀；3、布；4、表示退出");
		while ((result = user.chuquan()) != 4) {
			count++;
			// 将1,2,3==>石头，剪刀，布
			String chuQun = getChuquan(result);
			// ((int)(Math.random()*3))+1;
			int dianNaoQuan = computer.chuquan();
			String owner = "";
			int userIsOwner = userIsOwner(result, dianNaoQuan);
			if (userIsOwner==1) {
				user.jifen += 1;
				owner = user.name;
			} else if(userIsOwner==3) {
				computer.jifen += 1;
				owner = "电脑";
			}else{
				owner="没有人";
			}
			System.out.printf("%s出的是：%s,%s出的是:%s;%s胜出", user.name, chuQun,
					"电脑", getChuquan(dianNaoQuan), owner);
			System.out.println("请出拳:1、石头；2、剪刀；3、布；4、表示退出");

		}
		// 5、输入n退出对战，显示最终结果
		System.out.printf("总共玩了%d盘：%s赢了%d盘；%s赢了%d盘", count, user.name,
				user.jifen, "电脑", computer.jifen);

	}

	// x,y.x+1==y.x-2==y
	private static int userIsOwner(int x, int y) {
		if (x + 1 == y || x - 2 == y)
			return 1;
		if (x == y)
			return 2;
		return 3;
	}

	// 将1,2,3==>石头，剪刀，布
	private static String getChuquan(int result) {
		switch (result) {
		case 1:
			return "石头";
		case 2:
			return "剪刀";
		case 3:
			return "布";
		default:
			return "错误";
		}
	}

	private static void initPlay() {
		user = new User();
		computer = new Computer();

	}
}
